package com.acme.bankapp.domain.bank.account;

public class CheckingAccount extends AbstractAccount {
	private double overdraft;
	
	public CheckingAccount(double balance, double overdraft) throws Exception {
		super(balance);
		if (overdraft <= 0)
			throw new Exception("Value of overdraft must be positiv");
		this.overdraft = overdraft;
	}
	
	@Override
	public void withdraw(double x) throws Exception {
		if (x < 0) {
			throw new Exception("Diff to balance less zero");
		}
		
		if (super.balance >= x) {
			super.withdraw(x);
		}
		else if (super.balance + overdraft < x) {
			throw new Exception("Balance and Overdraft less diff");
		} else {
			super.balance =  (x - overdraft);
		}
	}
	
	@Override
	public double maximumAmountToWithdraw() {
		return super.maximumAmountToWithdraw() + overdraft;
	}
}
